import requests


class Session:
    '''
    会话类,所有测试用例共用一个会话类对象,
    第一次获取对象时会完成登录再返回对象
    后面再获取对象时直接返回这个对象
    '''
    __session = None

    @classmethod
    def get_session(cls):
        '''
        该方法不用传入参数,返回同一个Session对象
        :return:
        '''
        if cls.__session is None:
            cls.__session = requests.Session()
        return cls.__session

    @classmethod
    def close_session(cls):
        cls.__session.close()
        cls.__session = None

    @classmethod
    def login(cls):
        url = "http://120.53.243.26:8080/WoniuBoss4.0/login/userLogin"
        data = {"userName":"WNCD000", "userPass":"woniu123", "checkcode":"0000","remember":"Y"}
        session = cls.get_session()
        resp = session.post(url=url, data=data)
        return session

if __name__ == '__main__':
    res = Session.login()
    print(res)


